package de.slothsoft.wasbinich.core.util;

import java.text.ChoiceFormat;
import java.text.MessageFormat;
import java.util.Locale;

import de.slothsoft.wasbinich.core.GameResult;

public final class GameResultUtil {

    public static String buildPercentAndRatingString(GameResult gameResult) {
	return buildPercentAndRatingString(gameResult, Locale.getDefault());
    }

    public static String buildPercentAndRatingString(GameResult gameResult, Locale locale) {
	int percent = gameResult.entireAnswers == 0 ? 0 : gameResult.correctAnswers * 100 / gameResult.entireAnswers;
	return MessageFormat.format(Messages.getString("GameResultUtil.ratingPattern", locale), percent, //$NON-NLS-1$
		buildRatingString(gameResult, locale));
    }

    public static String buildRatingString(GameResult gameResult) {
	return buildRatingString(gameResult, Locale.getDefault());
    }

    public static String buildRatingString(GameResult gameResult, Locale locale) {
	if (gameResult.entireAnswers == 0)
	    return Messages.getString("GameResultUtil.zeroTries", locale); //$NON-NLS-1$
	int percent = gameResult.correctAnswers * 100 / gameResult.entireAnswers;
	return new ChoiceFormat(Messages.getString("GameResultUtil.ratings", locale)).format(percent); //$NON-NLS-1$
    }

    private GameResultUtil() {
	// hit me baby one more time
    }
}
